<template>
    <div class="container">
        <headerView class="header" :headerTitle="headerTitle" />
        <div class="content-item">
            <div class="content-btn"><el-button type="primary" @click.prevent="addDiary">上传</el-button></div>
            <div class="content">
                <div class="content-row">
                    <label>标题</label>
                    <el-input v-model="form.name" maxlength="20" placeholder="最多20个字..." />
                </div>
                <div class="content-row">
                    <label>内容</label>
                    <el-input v-model="form.content" maxlength="500" show-word-limit
                        style="width: 100%;font-size: 12px;" :autosize="{ minRows: 5 }" type="textarea"
                        placeholder="最多500个字..." />
                </div>
            </div>
        </div>
    </div>
</template>

<script setup name="AddDiary">
import { ref } from 'vue';
import headerView from '@/components/Header/backHeader.vue'
import service from '@/utils/request';
import router from '@/router';
const headerTitle = ref({ title: '写日记' });
const form = ref({
    name: '',
    content: '',
});
const addDiary = () => {
    service({
        url: 'api/Diarys',
        method: 'post',
        data: {
            userId: 0,
            title: form.value.name,
            content: form.value.content,
            createTime: '2024-12-31T14:41:10.527Z',
        }
    }).then(res => {
        if (res != undefined) {
            if (res.status == 200) {
                router.go(-1);
                ElMessage({
                    message: '上传成功',
                    type: 'success',
                });
            }
        }
    });
};

</script>

<style scoped>
.container {
    width: 100vw;
    height: 100vh;
    background-color: #d9ebec;
}

.header {
    width: 100%;
    height: 60px;
    position: fixed;
    top: 0;
    left: 0;
    box-shadow: 0px 0px 10px 5px rgba(82, 81, 81, 0.1);
}

.content-item {
    width: 100%;
    height: calc(100%-60px);
    padding-top: 60px;
}

.content-btn {
    width: 80%;
    margin: 0 auto;
    margin-top: 10px;
    position: relative;
}

.content-btn button {
    position: absolute;
    right: 0;
}

.content {
    margin: 0 auto;
    padding-top: 50px;
    width: 81%;
    height: 100%;
}

.content-row {
    width: 100%;
    margin-bottom: 20px;
}

.content-row label {
    display: block;
    font-size: 14px;
    margin-bottom: 8px;
}
</style>